package com.link.base.base.attendance.controller;

import com.link.base.base.attendance.model.Attendance;
import com.link.base.base.attendance.service.AttendanceService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 上下班签到
 * @author : 李群
 * @date : 2018/4/18
 */
@RestController
@RequestMapping("/link/guide/app/attendance")
public class AttendanceController extends BasicController<Attendance> {
    @Resource
    private AttendanceService attendanceService;

    @Override
    public BasicService<Attendance> getBasicService() throws Exception {
        return attendanceService;
    }

    /**
     * 根据月份,获取对应的所有签到信息
     * @author 李群
     * @date 2019/12/12 18:47
     * @param entity 签到对象
     */
    @RequestMapping(value = "/queryAllByMonth", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Map<String, Object> queryAllByMonth(Attendance entity, HttpSession session, HttpServletRequest request,
                                               HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            Map<String, Attendance> attendanceMap = attendanceService.queryAllByMonth(entity);
            result.put("success", true);
            result.put("result", attendanceMap);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", new ArrayList<T>());
            result.put("message", e.getMessage());
        }
        return result;
    }
}
